******************************************
* Title: rwanda_jde_tableA15.do
* Author: Todd Pugatch
* Last update: June 10 2024
* Description: analysis for Blimpo and Pugatch, "Entrepreneurship Education
*	and Teacher Training in Rwanda," Stage 2 Registered report, Journal of 
*	Development Economics
* Inputs: 	teacher_merge_jde.dta
* Outputs: 	rwanda_jde_tableA15.[txt/out]
* Notes: produces Table A15
*******************************************
* Set environment
local start=`"$S_TIME"'
clear
clear matrix
clear mata
graph drop _all
program drop _all
cap log close
set more off

* Set directories 
*global main "[SET MAIN DIRECTORY HERE]"
	global rawdata "$main/01_data/01_raw"
	global cleandata "$main/01_data/02_clean"
	global dofiles "$main/02_dofiles"
	global results "$main/03_results"
	global temp "$main/04_output"

* begin log file
log using "$temp/rwanda_jde_tableA15.txt", text replace

/* Are students presenting in Skills Lab?
	--exploratory analysis, not in analysis plan
	--produce columns 1-6 of Table P3, replacing overall active instruction time
		with student presentation as outcome*/

* ACTIVE INSTRUCTION TIME: teacher observation data
/*Goal: produce columns 1-6 of Table P3
	Uses endline teacher classroom observations (Stallings tool).
	Regress student presentation time on treatment status, controlling
		for randomization strata.
	Note that baseline data (BTQ300-302) only available for subset of teachers.*/
qui use "$cleandata/teacher_merge_jde.dta", clear

* restrict to teachers with classes observed at endline
qui keep if insample_obs_el==1

* prep missing values for teachers without baseline outcome
qui su pedagogy_active_index_bl if treatment==0 & insample_bl==1
qui replace pedagogy_active_index_bl=r(mean) if insample_bl!=1
qui gen pedagogy_active_index_blm=(insample_bl!=1)
lab var pedagogy_active_index_blm "missing value for `y0'"

* regressions: Table P3, columns 1-6
local stat ""control mean",mu_c,"baseline mean",mu_0"
local Y "mainact_teacher_present_pct mainact_teacher_present_0_27 mainact_teacher_present_28_52"
local act "qanda present pradrill pwork silentwork copying assign uninv classmgt outroom"
local Y0 "pedagogy_active_index_bl pedagogy_active_index_blm"

/*all observed classes: cols 1-3*/
/*full observation*/

* column 1: demo
	qui areg mainact_teacher_demo_pct treatment `Y0', a(strata) robust
	qui su mainact_teacher_demo_pct if treatment==0 & e(sample)
	scalar define mu_c=r(mean)
	qui su pedagogy_active_index_bl if insample_bl==1 & e(sample)
	scalar define mu_0=r(mean)
	outreg2 treatment using "$results/rwanda_jde_tableA15.xls", se excel nolabel nocons addstat(`stat') replace
	
* columns 2-3
foreach a in `act' {
	qui areg mainact_teacher_`a'_pct treatment `Y0', a(strata) robust
	qui su mainact_teacher_`a'_pct if treatment==0 & e(sample)
	scalar define mu_c=r(mean)
	qui su pedagogy_active_index_bl if insample_bl==1 & e(sample)
	scalar define mu_0=r(mean)
	outreg2 treatment using "$results/rwanda_jde_tableA15.xls", se excel nolabel nocons addstat(`stat') append
}

/*first half only*/
local act "demo qanda present pradrill pwork silentwork copying assign uninv classmgt outroom"
foreach a in `act' {
	qui areg mainact_teacher_`a'_0_27 treatment `Y0', a(strata) robust
	qui su mainact_teacher_`a'_0_27 if treatment==0 & e(sample)
	scalar define mu_c=r(mean)
	qui su pedagogy_active_index_bl if insample_bl==1 & e(sample)
	scalar define mu_0=r(mean)
	outreg2 treatment using "$results/rwanda_jde_tableA15.xls", se excel nolabel nocons addstat(`stat') append
}

/*second half only*/
foreach a in `act' {
	qui areg mainact_teacher_`a'_28_52 treatment `Y0', a(strata) robust
	qui su mainact_teacher_`a'_28_52 if treatment==0 & e(sample)
	scalar define mu_c=r(mean)
	qui su pedagogy_active_index_bl if insample_bl==1 & e(sample)
	scalar define mu_0=r(mean)
	outreg2 treatment using "$results/rwanda_jde_tableA15.xls", se excel nolabel nocons addstat(`stat') append
}

local end=`"$S_TIME"' 
di "`start'"
di "`end'"
log close
